<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
// namespace
window.semantic = {
	domain : {
		static : "${static_server }",
		dynamic : "${dynamic_server }",
		domain : "${cookie_domain }"
	},
	handler : {}
};

// ready event
semantic.ready = function() {
	
	$.fn.api.settings.api = {
		'get code' : 'http://' + semantic.domain.dynamic + '/user/{email}/code.do',
		'reg user' : 'http://' + semantic.domain.dynamic + '/user/{email}/reg.do',
		'login user' : 'http://' + semantic.domain.dynamic + '/user/{email}/login.do',
		'query enroll by score' : 'http://' + semantic.domain.dynamic + '/enroll/queryBySocre.do',
		'query student location distribution' : 'http://' + semantic.domain.dynamic + '/dis/lctDis.do',
		'query student batch distribution' : 'http://' + semantic.domain.dynamic + '/dis/batchDis.do',
		'query student major distribution' : 'http://' + semantic.domain.dynamic + '/dis/majorDis.do',
		'query top10 college by location' : "//" + semantic.domain.dynamic + "/dis/top10College.do?location={region}",
		'query solution' : "//" + semantic.domain.dynamic + "/solution/query.do?score={score}&subject={subject}&range={range}&batchs={batchs}&collegeIds={collegeIds}&descriptionIds={descriptionIds}&collegeTypes={collegeTypes}&q_2={q_2}&q_9={q_9}&q_y={q_y}&highLine={highLine}&lowLine={lowLine}",
		'create solution' : "//" + semantic.domain.dynamic + "/solution/create.do"
	};
	
	$.fn.api.settings.successTest = function(response) {
		if (response && response.success === true) {
			return true;
		}
		if (response && response.success === false) {
			return false;
		}
		if (response && response.indexOf("http://d.gaokaozyt.cn/user/login.do") == -1) {
			return true;
		}
		if (response && response.indexOf("http://d.gaokaozyt.cn/user/login.do") != -1) {
			return false;
		}
		return false;  
	};
	
	$.fn.api.settings.onFailure = function(response, element) {
		console.log(response);
	};
	
	$.fn.dropdown.settings.message = {
			noResults     : '没有搜索到相关数据，请更换关键字再试试！',
			addResult     : '系统没有相关数据，可以点击我添加 <b>{term}</b>',
		    count         : '{count} 选择',
			maxSelections : '最多可选择 {maxCount}条',
	};
	
	$.fn.api.settings.beforeXHR = function(xhr) {
		 this.cross_domain = true;
		 this.cache = false;
		 this.xhrFields = {
             withCredentials: true
		 };
		 xhr.setRequestHeader('Accept', '*/*'); 
	};
	
	$('.ui.accordion').accordion();

	$('img[data-src]').visibility({
		type : 'image',
		transition : 'fade in',
		duration : 500
	});
	
	$('.inline.icon')
	  .popup({
	  })
	;
	
	var is_weixin = function is_weixin(){
		var ua = navigator.userAgent.toLowerCase();
		if(ua.match(/MicroMessenger/i)=="micromessenger") {
			return true;
	 	} else {
			return false;
		}
	};
	
	var isMobile = {
		    Android: function() {
		        return navigator.userAgent.match(/Android/i) ? true: false;
		    },
		    BlackBerry: function() {
		        return navigator.userAgent.match(/BlackBerry/i) ? true: false;
		    },
		    iOS: function() {
		        return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true: false;
		    },
		    Windows: function() {
		        return navigator.userAgent.match(/IEMobile/i) ? true: false;
		    },
		    any: function() {
		        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
		    }
		};
	
	semantic.is_weixin = is_weixin;
	semantic.is_mobile = isMobile.any;
	
	$("a[href!='javascript'][target='_blank']").on('click', function(e, a, b){
		if (is_weixin()) {
			$(this).attr('target', '_self');
		}
		return true;
	});
	
};

// attach ready event
$(document).ready(semantic.ready)